package cn.tedu.springboot.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class TsetSelect2 {
    private static Connection conn =null;
    private static PreparedStatement ps =null;
    private static ResultSet rs = null;

    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        String url ="jdbc:mysql://localhost:3306/tedu?useUnicode=true&characterEncoding=utf8";
        String user = "root";
        String psd  ="root";
        conn = DriverManager.getConnection(url,user,psd);
        String sql ="select id,name from location where id =? and name =? ";

        ps=conn.prepareStatement(sql);
        ps.setInt(1,1);
        ps.setString(2,"'or'1'='1");

        rs =ps.executeQuery();
        System.out.println(rs.next()==true?"记录存在":"记录不存在");
        rs.close();
        ps.close();
        conn.close();
    }
}
